def prs (a):
    for d in range(2, a):
        if a % d == 0:
            return False
    return True

t=int(input('Введите число:'))
if 1000 <= t <=9999:
    maxim=0
    f=[t, t%1000, t//10, t//100, t%100, t%1000//10, t//1000, t%1000//100, t//10%10, t%10]
    for i in f:
        if i > maxim and prs(i):
            maxim = i
    print(maxim)
else:
    print(0)





